/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-05-28 15:51:32
 * @LastEditors: kl2018
 * @LastEditTime: 2020-06-22 13:45:02
 */
import { message, Modal } from 'antd';
import { WeaLocaleProvider } from 'ecCom';

const { getLabel } = WeaLocaleProvider;

const success = [1, true];
const errors = [0, false];
class Base {
	showMsg = (type, msg, time = 3, showtype = '') => {
		if (success.indexOf(type) != -1 || showtype == 'success') {
			this.showSuccessMsg(msg, time);
		} else if (errors.indexOf(type) != -1 || showtype == 'errors') {
			this.showErrorMsg(msg, time);
		} else {
			this.showWarningMsg(msg, time);
		}
	}
	showSuccessMsg = (msg, time = 3, onClose) => {
		message.success(msg || getLabel(83551, '保存成功！'), time, onClose);
	}

	showErrorMsg = (msg, time = 3, onClose) => {
		message.error(msg || getLabel(84544, '保存失败！'), time, onClose);
	}
	showWarningMsg = (msg, time = 3, onClose) => {
		message.warning(msg || getLabel(506341, '数据异常,请联系管理员!'), time, onClose);
	}

	showConfirm = (title = getLabel(22575, '系统提醒消息'), content = '', onOk, onCancel,
				   okText = getLabel(83446, '确定'), cancelText = getLabel(201, '取消')) => {
		Modal.confirm({
			title,
			content,
			okText,
			cancelText,
			onOk: () => {
				typeof onOk == 'function' && onOk();
			},
			onCancel: () => {
				typeof onCancel == 'function' && onCancel();
			},
		});
	}

	showWarning = (title = getLabel(22575, '系统提醒消息'), content = '', onCancel) => {
		Modal.warning({
			title,
			content,
			okText: getLabel(826, '确定'),
			onOk: () => {
				typeof onCancel == 'function' && onCancel();
			},
			onCancel: () => {
				typeof onCancel == 'function' && onCancel();
			},
		});
	}

	/**
	 * 验证签字意见是否填写成功
	 * @param params
	 * @returns {boolean}
	 */
	checkRemark = (params = {}) => {
		const { remark = '' } = params;
		let checkpass = false;
		if (remark.length > 0) {
			checkpass = true;
		}
		return checkpass;
	}
}
export { Base };
